package br.com.domain;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.Size;

import org.hibernate.validator.constraints.NotEmpty;

@Entity
@Table(name="tb_perfil")
public class Perfil extends Domain {
	
	/**************************************************************************/
	/**                             CONSTRUTOR                               **/
	/**************************************************************************/
	
	public Perfil() {
		super();
		listPerfilMenu = new ArrayList<PerfilMenu>();
	}
   
	/**************************************************************************/
	/**                                ATRIBUTOS                             **/
	/**************************************************************************/
	private static final long serialVersionUID = 1L;
	
	@Id
	@GeneratedValue (strategy = GenerationType.IDENTITY)
	@Column         (name ="idPerfil")
	private Integer id;
	
    @NotEmpty 
	@Size(max=120)  
	@Column(name="nome", length=100)
	private String nome;
	
	@Column(name="administrador", columnDefinition="boolean default false")
	private Boolean administrador;
	
	@Column(name="fixo", columnDefinition="BOOLEAN")
	private Boolean fixo;
	
	/********************************************************************/
	/** 															   **/
	/**                       RELACIONAMENTOS         				   **/
	/**															 	   **/
	/********************************************************************/
	
	@OneToMany(fetch = FetchType.EAGER, mappedBy = "perfil", cascade=CascadeType.ALL, 
			   targetEntity = PerfilMenu.class)
	private List<PerfilMenu> listPerfilMenu;
	
	
	/**************************************************************************/
	/**                              GET's E SET's                           **/
	/**************************************************************************/
	
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getNome() {
		return nome;
	}

	public void setNome(String nome) {
		this.nome = nome;
	}

	public Boolean getAdministrador() {
		if (administrador == null)
			administrador = false;
		return administrador;
	}

	public void setAdministrador(Boolean administrador) {
		this.administrador = administrador;
	}
	
	
	public List<PerfilMenu> getListPerfilMenu() {
		return listPerfilMenu;
	}

	public void setListPerfilMenu(List<PerfilMenu> listPerfilMenu) {
		this.listPerfilMenu = listPerfilMenu;
	}

	public Boolean getFixo() {
		return fixo;
	}

	public void setFixo(Boolean fixo) {
		this.fixo = fixo;
	}

	
	/********************************************************************/
	/**                EQUALS E HASH CODE  - RETIRAR LIST's            **/
	/********************************************************************/
	
	

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((administrador == null) ? 0 : administrador.hashCode());
		result = prime * result + ((fixo == null) ? 0 : fixo.hashCode());
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result
				+ ((listPerfilMenu == null) ? 0 : listPerfilMenu.hashCode());
		result = prime * result + ((nome == null) ? 0 : nome.hashCode());
		return result;
	}
	
	
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Perfil other = (Perfil) obj;
		if (administrador == null) {
			if (other.administrador != null)
				return false;
		} else if (!administrador.equals(other.administrador))
			return false;
		if (fixo == null) {
			if (other.fixo != null)
				return false;
		} else if (!fixo.equals(other.fixo))
			return false;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		if (nome == null) {
			if (other.nome != null)
				return false;
		} else if (!nome.equals(other.nome))
			return false;
		return true;
	}

	
	
}
